﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap"%>
<%@ page import="oneroom.admin.oneroom.roomModel" %>
<jsp:useBean id="room" scope="page" class="oneroom.admin.oneroom.roomDao" />
<jsp:useBean id="dao" scope="page" class="oneroom.admin.oneroom.roomDao" />
<%
	
	//session 등급, 사용자구분값 처리
	HashMap	paramMap	= new HashMap();
	String	id	= (String)session.getAttribute("id") == null ? "" : (String)session.getAttribute("id");
	String	authorize	= (String)session.getAttribute("authorize") == null ? "" : (String)session.getAttribute("authorize");
	String	grade	= (String)session.getAttribute("grade") == null ? "" : (String)session.getAttribute("grade");
	String redirectUrl = "";
	if (session.getAttribute("id") != null &&
			((String)session.getAttribute("id")).equals("") == false) {
	} else {
		redirectUrl = "/room/member/login.jsp";
		response.sendRedirect(redirectUrl);
	}
	paramMap.put("authorize",authorize);
	paramMap.put("grade",grade);
	paramMap.put("id",id);   
	HashMap	returnMap	= new HashMap();
	returnMap	= room.getSelectCnt(paramMap);
	int one_cnt		=	(int)Double.parseDouble(returnMap.get("one_cnt").toString());
	int two_cnt		=	(int)Double.parseDouble(returnMap.get("two_cnt").toString());
	int three_cnt	=	(int)Double.parseDouble(returnMap.get("three_cnt").toString());
	int apt_cnt		=	(int)Double.parseDouble(returnMap.get("apt_cnt").toString());
	int home_cnt	=	(int)Double.parseDouble(returnMap.get("home_cnt").toString());
	int office_cnt	=	(int)Double.parseDouble(returnMap.get("office_cnt").toString());
	String pageName = "room_list.jsp";
	String viewName = "room_view.jsp";
	int     giSelectPage  	= Integer.parseInt(request.getParameter("txtSelectPage") == null ? "0" :request.getParameter("txtSelectPage"));			//현재 선택된 페이지 저장
	int     giSelectBlock 	= Integer.parseInt(request.getParameter("txtSelectBlock") == null ? "0" :request.getParameter("txtSelectBlock"));			//현재 선택된 블락페이지 저장
	String searchGubn	= request.getParameter("searchGubn") == null ? "" : request.getParameter("searchGubn");
	String searchValue	= request.getParameter("searchValue") == null ? "" : request.getParameter("searchValue");
	String roomkind		= request.getParameter("roomkind") == null ? "" : request.getParameter("roomkind");
	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 10;  			// 한페이지에 나타내고자 하는 List수
	int     giBlockSize   	= 10;   		// Block의 수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giStartPos    	= 0;   			// 시작 List 위치
	int     giTotPage     	= 0;   			// 총 Page수
	int     giTotBlock    	= 0;   			// 총 Block수
	//  넘겨온 값 받기(List페이지 관련)...
	if ( giSelectPage  >  0 ) { 			// 선택된 Page값이 있을경우....     
		giCurPage  = giSelectPage;   	// 현재Page = 선택된Page 
		giCurBlock = giSelectBlock;  	// 블락page = 선택된 블락 page
	}
	//쿼리를 돌려서 가지고 오는 값
	List list = dao.getMyList(searchGubn,searchValue, giSelectPage, giPageSize, id);
	int     historycnt       	= 0;	//업데이트 이력 횟수	
	historycnt = dao.getDateupdateHistory(id); 			// 총 list 수	
	if (list.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = dao.getMyCount(id); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
		giTotBlock = giTotPage / giBlockSize;
		if (giTotPage % giBlockSize != 0) {
			giTotBlock = giTotBlock + 1;		// 총 Block수를 구한다...
		}
	}
	int tot_cnt = 0;
	if(grade.equals("1")){
		tot_cnt = 300;
	}else if(grade.equals("2")){
		tot_cnt = 100;
	}else if(grade.equals("3")){
		tot_cnt = 60;
	}else if(grade.equals("4")){
		tot_cnt = 30;
	}else if(grade.equals("5")){
		tot_cnt = 3;		
	}else if(grade.equals("6")){
		tot_cnt = 1;		
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>원룸몬스터</title>

<link href="/room/css/all.css" rel="stylesheet" type="text/css" />
<script src="/room/script/swfobject_modified.js" type="text/javascript"></script>
<script src="/room/script/common.js" type="text/javascript"></script>
<script src="/room/script/jquery-1.3.2.min.js" type="text/javascript" ></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	$('#wrtBtn').click(function() {
	<%if (tot_cnt == giRecordcnt || tot_cnt < giRecordcnt){ %>
		alert("더 이상 매물을 등록 할 수 없습니다");
	<%}else{%>
		window.location.href="room_write.jsp";
	<%}%>
	});
});

function goView(oneroomseq){
	document.frmView.oneroom_seq.value = oneroomseq;
	document.frmView.submit();
}

function dateBtn(){
	var str =  document.getElementsByName("chkbox");
	var count = 0;
	<% if(historycnt <= 3){%>
    for (var i = 0; i <str.length; i++) {
    	if(str[i].checked){       
    		count += 1;
        }
    }	
	if (count == 0) { //체크박스가 여러 개일 경우
		alert("하나라도 체크를 해야합니다.");
	}else {
		var frm = document.mfrm;
	    for (var i = 0; i <str.length; i++) {
	    	if(str[i].checked){       
				frm.oneroom_seq.value += str[i].value+",";
	        }
	    }
	    frm.gubun.value = "A";
		frm.action = "room_dbx.jsp";
		frm.submit();
	}
	<%}else{%>
	alert("날짜 업데이트 횟수를 초과 하였습니다.");
	<%}%>
}

function delBtn(){
	var str =  document.getElementsByName("chkbox");
	var count = 0;
    for (var i = 0; i <str.length; i++) {
    	if(str[i].checked){       
    		count += 1;
        }
    }	
	if (count == 0) { //체크박스가 여러 개일 경우
		alert("하나라도 체크를 해야합니다.");
	}else {
		var frm = document.mfrm;
	    for (var i = 0; i <str.length; i++) {
	    	if(str[i].checked){       
				frm.oneroom_seq.value += str[i].value+",";
	        }
	    }
	    frm.gubun.value = "MD";
		frm.action = "room_dbx.jsp";
		frm.submit();
	}
}

function chk_val( str ) {
    var chk_box = document.getElementsByName("chkbox");
    var chk_len = chk_box.length;
    for( var lo = 0; lo < chk_len; lo++) {
           str == 'rev' ? chk_box[lo].checked == true ? chk_box[lo].checked = false : chk_box[lo].checked = true : '';
    }
}
//-->
</script>	
</head>

<body>
<div align="center"> 

 <div id="content">

<!----------------왼쪽---------------->  
<%@ include file="/room/common/left.jsp" %>
<!----------------왼쪽끝---------------->  

<!----------------가운데 시작----------------> 
 <div id="rgt">
  <div id="con01">
   <div class="top bb1"><img src="/room/img/txt_top.gif" /></div>
   <div id="sch-adress"></div>
   
<div class="list h550">
 <div class="pb10"><img src="/room/img/line_blue.gif" width="32" height="2" /></div>
      <div class="pb20"><span style="font-size:11px;">Home >회원> <span style="color:#000;">마이페이지</span></span></div>
      <div> 
       <div class="tit">my 매물리스트 </div>   	
      </div>
<!---------------- 내용시작----------------> 
<table width="595" border="0" cellspacing="0" cellpadding="0" style="padding-bottom:30px;">
  <tr>
    <td>
	<p style="font-size:15px;">총 매물등록 가능 수 : <span><%=tot_cnt%></span> <br />원룸:<span><%=one_cnt%></span>건,  투룸:<span><%=two_cnt%></span>건,  쓰리룸:<span><%=three_cnt%></span>건,  아프트:<span><%=apt_cnt%></span>건,  주택/빌라:<span><%=home_cnt%></span>건,  오피스텔:<span><%=office_cnt%></span>건</p>    
     </td>
  </tr>
</table>

<form name="mfrm" id="mfrm" method="post">   
<input type="hidden" name="gubun" value="" />
<input type="hidden" name="oneroom_seq" value="" />
<table width="595" border="0" cellspacing="0" cellpadding="0">
<col width="5%" />
<col width="8%" />
<col/>
<col width="40%" />
<col width="15%" />
<col width="10%" />
  <tr>
    <td class="ac fw bt2 bb1 h30 bg_g"><input type="checkbox" onclick="chk_val('rev')" /></td>
    <td class="ac fw bt2 bb1 h30 bg_g">번호</td>
    <td class="ac fw bt2 bb1 h30 bg_g">이미지</td>
    <td class="ac fw bt2 bb1 h30 bg_g">제목</td>
    <td class="ac fw bt2 bb1 h30 bg_g">등록자</td>
    <td class="ac fw bt2 bb1 h30 bg_g">등록일</td>
  </tr>
<%
	if(list != null && list.size() > 0){
		giCount  = 1;
		giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
		giStartPos = ((giCurPage - 1) * giPageSize) + 1;
		for(int i = 0; i<list.size(); i++){
			roomModel model = (roomModel)list.get(i);
%>  
	<tr>
	<td class="ac bb1 h30"><input type="checkbox" name="chkbox" value="<%=model.getOneroom_seq() %>" /></td>
	<td class="ac bb1 h30"><%=giRecordcnt %></td>
	<td class="ac bb1 h30">
		<%if(model.getPhoto1_main().equals("1")){ %>
			<img src="/download/<%=model.getPhoto1_small() %>?name=<%=model.getPhoto1_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("2")){ %>
			<img src="/download/<%=model.getPhoto2_small() %>?name=<%=model.getPhoto2_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("3")){ %>
			<img src="/download/<%=model.getPhoto3_small() %>?name=<%=model.getPhoto3_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("4")){ %>
			<img src="/download/<%=model.getPhoto4_small() %>?name=<%=model.getPhoto4_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("5")){ %>
			<img src="/download/<%=model.getPhoto5_small() %>?name=<%=model.getPhoto5_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("6")){ %>
			<img src="/download/<%=model.getPhoto6_small() %>?name=<%=model.getPhoto6_small() %>&kind=img" />
		<%} %>
	</td>
	<td class="fw bb1 h30"><a href="javascript:goView('<%=model.getOneroom_seq() %>')"><%=model.getTitle() %></a></td>
	<td class="ac bb1 h30"><%=model.getCreateid() %></td>
	<td class="ac bb1 h30"><%=model.getCreatedate() %></td>
	</tr>
	<%
			giCount = giCount + 1;
			giRecordcnt = giRecordcnt - 1;
		}
	}else{
	%>
	<tr><td class="ac bb1 h30" colspan="6">등록된 내용이 없습니다.</td></tr>
	<%
	}
	%>
</table>
</form>
   <div class="pt15">
    <table width="595" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<%@ include file="/room/common/pages.jsp" %>
     </td>
    <td width="50" align="right">
	<a class="d" href="#" onclick="delBtn();" ><div class="btn_b87">삭제</div></a>
	</td>         
    <td width="50" align="right">
	<a class="d" href="#" onclick="dateBtn();" ><div class="btn_b87">날짜 업데이트</div></a>
	</td>    
    <td width="50" align="right">
    <a class="d" href="#" id="wrtBtn"><div class="btn_b47">등록</div></a>
    </td>
  </tr>
</table>
</div>

<div class="pt15" style="width:595px;">
<!-- 
<form action="list.jsp" name="frm" id="frm" method="post">   
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<select name="searchGubn" style="width:80px;">
		<option value="all" >전체</option>
	</select>
	<input type="text" name="searchValue" style="width:150px;"/>				
     </td>
    <td style="padding-left:10px;"><a class="d" href="#" id="searchBtn"><div class="btn_b47">검색</div></a></td>
  </tr>
</table>
</form>
 -->
</div>
<!----------------내용끝----------------> 

	</div>
</div>  
<!----------------가운데 끝---------------->
<form action="room_view.jsp" method="post" name="frmView" >
<input type="hidden" name="searchGubn" value="<%=searchGubn %>"/>
<input type="hidden" name="searchValue" value="<%=searchValue %>"/>
<input type="hidden" name="txtSelectPage" value="<%=giSelectPage %>"/>
<input type="hidden" name="txtSelectBlock" value="<%=giSelectBlock %>"/>
<input type="hidden" name="oneroom_seq" value=""/>
</form>


<!----------------오른쪽 시작---------------->  
<%@ include file="/room/common/right.jsp" %>  
<!----------------오른쪽 끝---------------->
</div>


<!-------------푸터영역----------> 
<%@ include file="/room/common/footer.jsp" %> 
<!-------------푸터영역----------> 
<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>
</body>
</html>